﻿using System;
using System.Collections.Generic;
using Metaspec;

class MyEntityVisitor : ICsEntityVisitor
{
	Dictionary<cs_entity, int> entitiesCount = new Dictionary<cs_entity, int>();

	public void visit(CsEntityNamespace entity) { visitEntity(entity); }
	public void visit(CsEntityBlock entity) { visitEntity(entity); }
	public void visit(CsEntityFormalParameter entity) { visitEntity(entity); }
	public void visit(CsEntityMethod entity) { visitEntity(entity); }
	public void visit(CsEntityClass entity) { visitEntity(entity); }
	public void visit(CsEntityStruct entity) { visitEntity(entity); }
	public void visit(CsEntityInterface entity) { visitEntity(entity); }
	public void visit(CsEntityEnum entity) { visitEntity(entity); }
	public void visit(CsEntityDelegate entity) { visitEntity(entity); }
	public void visit(CsEntityGenericParam entity) { visitEntity(entity); }
	public void visit(CsEntityConstant entity) { visitEntity(entity); }
	public void visit(CsEntityVariable entity) { visitEntity(entity); }
	public void visit(CsEntityBlockVariable entity) { visitEntity(entity); }
	public void visit(CsEntityProperty entity) { visitEntity(entity); }
	public void visit(CsEntityEvent entity) { visitEntity(entity); }
	public void visit(CsEntityLocalConstant entity) { visitEntity(entity); }
	public void visit(CsEntityLocalVariable entity) { visitEntity(entity); }
	public void visit(CsEntityAnonymousMethod entity) { visitEntity(entity); }

	void visitEntity(CsEntity entity)
	{
		if (!entitiesCount.ContainsKey(entity.e))
		{
			entitiesCount.Add(entity.e, 0);
		}
		++entitiesCount[entity.e];
	}

	int getCount(cs_entity e)
	{
		if (entitiesCount.ContainsKey(e))
			return entitiesCount[e];
		return 0;
	}

	public void print()
	{
		Console.WriteLine(string.Format("Total number of classes: {0}", getCount(cs_entity.ent_class)));
		Console.WriteLine(string.Format("Total number of structs: {0}", getCount(cs_entity.ent_struct)));
		Console.WriteLine(string.Format("Total number of delegates: {0}", getCount(cs_entity.ent_delegate)));
		Console.WriteLine(string.Format("Total number of enums: {0}", getCount(cs_entity.ent_enum)));
		Console.WriteLine(string.Format("Total number of methods: {0}", getCount(cs_entity.ent_method)));
		Console.WriteLine(string.Format("Total number of properties: {0}", getCount(cs_entity.ent_property)));
		Console.WriteLine(string.Format("Total number of events: {0}", getCount(cs_entity.ent_event)));
		Console.WriteLine(string.Format("Total number of variables: {0}", getCount(cs_entity.ent_variable)));
		Console.WriteLine(string.Format("Total number of constants: {0}", getCount(cs_entity.ent_constant)));
	}
}